<template>
	<view class="chart-container">
		<u-toast ref="manageLogin"></u-toast>
		<view class="up-back-container">
			<view class="up-back-icon-item iconfont icon-x" @click="back"></view>
		</view>
		<view class="center-monitor-icon-item-container">
			<view class="center-up-monitor-icon-item iconfont icon-xianshiqi-copy">
				<view class="logo-container">
					<image src="../../static/png/logo.png" class="my-logo"></image>
				</view>
			</view>
			<view class="center-down-name">记账后台管理确认</view>
		</view>
		<view class="manage-login-confirm-container" @click="loginPc">登录</view>
	</view>
</template>

<script>
	import {goBack} from '../../util/util.js';
	import { getValue } from '../../util/auth.js';
	export default {
		data() {
			return {
				userId: '',				// 用户id
				key: '',				// 二维码标识
			}
		},
		onLoad: function(option) {
			if (option && option.key) {
				// 说明扫码成功，并且是登录PC端的二维码
				this.key = option.key;
				// 发一个请求，通过key来知道是谁，然后和username
			}
		},
		onReady() {
			var value = getValue();
			if (value) {
				this.userId = JSON.parse(value).userId;
			} else {
				this.errorTips(this.$refs.manageLogin, "获取用户信息失败，请重试", null);
				uni.switchTab({
					url: '/pages/setting/index'
				})
			}
		},
		methods: {
			/**
			 * 登录pc
			 */
			loginPc() {
				var that = this;
				console.log("this.userId", that.userId);
				console.log("this.key", that.key);
				if (that.userId && that.key) {
					that.$req.loginPc("key=" + that.key + "&userId=" + that.userId).then(res => {
						if (res.success) {
							console.log("res111", res);
							that.successTips(that.$refs.manageLogin, "登录成功", null);
							// that.msg("登录成功");
							that.key = "";
							that.userId = "";
							setTimeout(() => {
								uni.switchTab({
									url: '/pages/setting/index'
								})
							}, 2000)
							// console.log("进来了");
						} else {
							// that.msg(res.message);
							that.errorTips(that.$refs.manageLogin, res.message, null);
						}
					})
				} else {
					console.log("参数不够，无法登录");
					that.errorTips(that.$refs.manageLogin, "参数不够，无法登录", null);
				}
			},
			back() {
				if (this.key) {
					this.$req.cancelLoginPc(this.key).then(res => {
						console.log("取消扫码登录请求结果", res);
					})
				}
				uni.switchTab({
					url: '/pages/setting/index'
				})
				// goBack();
			}
		}
	}
</script>

<style lang="scss">
	/* 设置背景颜色 */
	page {
		/* background-color: #fefdf8; */
		padding-top: var(--status-bar-height);
		background-color: $themeColor;
		box-sizing: border-box;
		width: 100vw;

	}
	
	.chart-container {
		width: 100%;
		height: 100;
		padding: 35rpx;
		box-sizing: border-box;
		
		.up-back-container {
			width: 100%;
			height: 50rpx;
			
			.up-back-icon-item {
				font-size: 35rpx;
				color: $typefaceGreyColor;
			}
		}
		
		.center-monitor-icon-item-container {
			width: 100%;
			height: 650rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
			
			.center-up-monitor-icon-item {
				font-size: 270rpx;
				position: relative;
				color: #bfbfbf;
				
				.logo-container {
					position: absolute;
					width: 80rpx;
					height: 80rpx;
					top: 25%;
					left: 35%;
					display: flex;
					justify-content: center;
					align-items: center;
					
					.my-logo {
						width: 100%;
						height: 100%;
					}
				}
			}
			
			.center-down-name {
				
			}
		}
		
		.manage-login-confirm-container {
			width: 100%;
			height: 80rpx;
			display: flex;
			justify-content: center;
			align-items: center;
			color: white;
			background-color: $themeYellowColor;
			border-radius: 10rpx;
		}
	}
</style>
